import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/home/HomeView.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'login',
    component: () => import('../views/login/LoginView.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta: {
      isLogin: true
    },
    children: [{
        path: '/welcome',
        name: 'welcome',
        component: () => import('../views/welcome/WelComeView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/user',
        name: 'user',
        component: () => import('../views/user/UserView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/rights',
        name: 'rights',
        component: () => import('../views/permissions/RightsView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import('../views/permissions/RolesView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import('../views/goods/manage/GoodsView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/params',
        name: 'params',
        component: () => import('../views/goods/params/ParamsView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/addgoods',
        name: 'addgoods',
        component: () => import('../views/goods/addgoods/AddGoods.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/categories',
        name: 'categories',
        component: () => import('../views/goods/category/CategoriesView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/orders',
        name: 'order',
        component: () => import('../views/orders/OrderView.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/ToTuBiao',
        name: 'ToTuBiao',
        component: () => import('../views/datas/ToTuBiao.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/settings',
        name: 'settings',
        component: () => import('../views/seting/SetTings.vue'),
        meta: {
          isLogin: true
        }
      }
    ]
  }
];


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, form, next) => {
  if (to.meta.isLogin) {
    if (localStorage.getItem('token')) {
      next();
    } else {
      next('/')
    }
  } else {
    next();
  }

})
export default router